<script lang="ts" setup name="AsmePersonInfo">
import { getListByConditionsWithPage, urls } from '@/index';
import type { AsmePersonInfo, AsmePersonInfoQueryCondition, DialogModel } from '@/index.d';
import { useRequest } from 'vue-request';
import DetailDialog from './DetailDialog.vue';
const title = '美标人员信息';
const queryCondition = reactive<AsmePersonInfoQueryCondition>({
  deleted: false,
  change: false,
  currentPage: 1,
  pageSize: 20
});

const resetQueryCondition = () => {
  queryCondition.currentPage = 1;
  queryCondition.pageSize = 20;
  delete queryCondition.username;
};

const getAsmePersonListWithPagePromise = () => {
  return getListByConditionsWithPage<AsmePersonInfo>(urls.asmePersonInfo, queryCondition);
};

const {
  data: getAsmePersonListData,
  run: getAsmePersonListRun,
  loading: getAsmePersonListLoading
} = useRequest(getAsmePersonListWithPagePromise);

const handleResetQuery = () => {
  resetQueryCondition();
  getAsmePersonListRun();
};

const detailDialogModel = reactive<DialogModel<AsmePersonInfo>>({
  visible: false,
  title,
  type: 'view',
  id: 0,
  change: false
});

watch(
  () => detailDialogModel.visible,
  (value: boolean) => {
    if (!value && detailDialogModel.change) {
      getAsmePersonListRun();
      detailDialogModel.change = false;
    }
  }
);
</script>
<template>
  <HqContainerTable
    :base-url="urls.asmePersonInfo"
    :title="title"
    :loading="getAsmePersonListLoading"
    :total="getAsmePersonListData?.total"
    :table-data="getAsmePersonListData?.records"
    v-model:pageSize="queryCondition.pageSize"
    v-model:current-page="queryCondition.currentPage"
    @handle-query="getAsmePersonListRun"
    @handle-reset-query="handleResetQuery"
    v-model:detail-dialog-model="detailDialogModel"
    :operate-column="true"
  >
    <template #search>
      <hq-col kind="search">
        <el-select
          v-model="queryCondition.username"
          filterable
          clearable
          placeholder="请选择人员"
          @change="getAsmePersonListRun"
        >
          <hq-user-options />
        </el-select>
      </hq-col>
    </template>
    <template #button> </template>
    <template #tableColumns>
      <hq-table-column prop="name" label="姓名" />
      <hq-table-column prop="username" label="账号" />
      <hq-table-column prop="workNo" label="工号" />
      <hq-table-column prop="totalTime" label="总时长" />
      <hq-table-column prop="utTime" label="utTime" />
      <hq-table-column prop="rtTime" label="rtTime" />
      <hq-table-column prop="mtTime" label="mtTime" />
      <hq-table-column prop="ptTime" label="ptTime" />
      <hq-table-column prop="ltTime" label="ltTime" />
      <hq-table-column prop="etTime" label="etTime" />
      <hq-table-column prop="vtTime" label="vtTime" />
    </template>
  </HqContainerTable>
  <DetailDialog v-model:dialog-model="detailDialogModel" v-if="detailDialogModel.visible" />
</template>
<style lang="scss" scoped></style>
